﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Xml.Linq;
using Chefbook.DataObjects;
using Chefbook.DataObjects.XmlSerialization;

namespace UnitTests.DataObjectsTests.XmlSerializationTests
{
    [TestFixture]
    public class CategoryXmlSerializerFixture
    {
        private XDocument doc;
        private List<Category> roots;

        [SetUp]
        public void Init()
        {
            doc = XDocument.Load("file.xml");
            roots = new List<Category>();

            Category tasties = new Category(null) { Name = "Tasties" };
            Category pasta = new Category(tasties) { Name = "Pasta" };
            Category chicken = new Category(pasta) { Name = "Chicken" };
            Recipe chickenShrimpScampi = new Recipe(chicken) { Name = "Chicken and Shrimp Scampi" };
            Recipe chickenFettuciniAlfredo = new Recipe(chicken) { Name = "Chicken Fettucini Alfredo" };
            Category beef = new Category(pasta) { Name = "Beef" };
            Recipe spaghettiAndMeatballs = new Recipe(beef) { Name = "Spaghetti and Meatballs" };
            Recipe lasagna = new Recipe(beef) { Name = "Lasagna" };
            Category pork = new Category(pasta) { Name = "Pork" };
            pork.AddRecipe(lasagna);
            Category seafood = new Category(pasta) { Name = "Seafood" };
            seafood.AddRecipe(chickenShrimpScampi);

            roots.Add(tasties);
        }

        [Test]
        public void TestReadingCategoryXml()
        {
            var expected = roots.ToList();
            var actual = CategoryXmlSerializer.DeserializeCategories(doc).ToList();
            Assert.AreEqual(expected.Count, actual.Count);
            for (int i = 0; i < expected.Count; i++)
            {
                Assert.True(expected[i].ValueEquals( actual[i]));
            }
        }

        [Test]
        public void TestWritingCategoryXml()
        {

            XDocument actual = CategoryXmlSerializer.SerializeCategories(roots);
            Assert.AreEqual(doc.ToString(), actual.ToString());
        }

    }
}
